package com.hmy.finance.controller.receiveAdjust;

import com.hmy.ccp.common.result.JsonResult;
import com.hmy.ccp.error.annotations.HmyGateWayController;
import com.hmy.finance.bo.receiveAdjust.request.QueryReceiveAdjustRequest;
import com.hmy.finance.bo.receiveAdjust.request.SaveReceiveAdjustRequest;
import com.hmy.finance.bo.receiveAdjust.request.SyncReceiveAdjustRequest;
import com.hmy.finance.service.receiveAdjust.ReceiveAdjustService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "应收调整")
@RestController
@Slf4j
@RequestMapping("/api/receiveAdjust")
@HmyGateWayController
public class ReceiveAdjustController {

    @Resource
    private ReceiveAdjustService receiveAdjustService;

    @PostMapping("/queryPage")
    public JsonResult queryPage(@RequestBody QueryReceiveAdjustRequest queryReceiveAdjustRequest) {
        return JsonResult.success(receiveAdjustService.queryPage(queryReceiveAdjustRequest));
    }

    @PostMapping("/query")
    public JsonResult query(@RequestBody QueryReceiveAdjustRequest queryReceiveAdjustRequest) {
        return JsonResult.success(receiveAdjustService.query(queryReceiveAdjustRequest));
    }

    @GetMapping("/queryAdjustRelatedContract/{contractId}")
    public JsonResult queryAdjustRelatedContract(@PathVariable("contractId") Long contractId) {
        return JsonResult.success(receiveAdjustService.queryAdjustRelatedContract(contractId));

    }

    @PostMapping("/save")
    public JsonResult save(@RequestBody @Validated({SaveReceiveAdjustRequest.Save.class}) SaveReceiveAdjustRequest
                                   saveReceiveAdjustRequest) {
        return JsonResult.success("SUCCESS", receiveAdjustService.save(saveReceiveAdjustRequest));
    }

    @PostMapping("/submit")
    public JsonResult submit(@RequestBody @Validated({SaveReceiveAdjustRequest.Submit.class}) SaveReceiveAdjustRequest
                                     saveReceiveAdjustRequest) {
        return JsonResult.success("SUCCESS", receiveAdjustService.submit(saveReceiveAdjustRequest));
    }

    @DeleteMapping("/delete/{adjustId}")
    public JsonResult delete(@PathVariable("adjustId") Long adjustId) {
        return JsonResult.success(receiveAdjustService.delete(adjustId));
    }

    @PostMapping("/sync")
    public JsonResult sync(@RequestBody SyncReceiveAdjustRequest syncReceiveAdjustRequest) {
        return JsonResult.success(receiveAdjustService.sync(syncReceiveAdjustRequest));
    }


}
